from route import *
from loadOsm import *
from distance import *
from near_by_road import *
data = LoadOsm("iise.osm")
node1=669862566
source=(11.2590659,75.7908983)
node=[]
name=[]
lat=[]
lon=[]
poiname=[]

for line in open("latloncalicut.b","r"):
    line=line.split(";")
    node.append(line[0])
    name.append(line[1])
    lat.append(line[2])
    lon.append(line[3])
    l=line[4]
    poiname.append(l[:-1])
poiselectname=[]
poilatlon=[]    
poi=raw_input("enter your place of interest:")
for i in range(len(poiname)):
    if poi==poiname[i]:
       a=(lat[i],lon[i])
       print i
       poilatlon.append(a)
       poiselectname.append(name[i])

#print poiselectname
nearest=displacement(source,poilatlon)
print "Nearest "+poi+"s "+"are:"
for i in nearest:
    print poiselectname[i]
destination=raw_input("Enter the name of the place:")
sellat,sellon=lat[name.index(destination)],lon[name.index(destination)]
node2=near_by_road(float(sellat),float(sellon))
node2=float(node2)    
transport="cycle"
router = Router(data)
result, route = router.doRouteAsLL(node1, node2, transport)
f=open("track","w")
distlat=[]
distlon=[]
for i in route:
    distlat.append(float(i[0]))
    distlon.append(float(i[1]))
    line=str(i[0])+';'+str(i[1])
    f.write(line)
    f.write("\n")
f.close()
dist=distance(distlat,distlon)
print dist

#if result == 'success':
#    print "Route: %s\n" % ",".join("%1.4f,%1.4f\n" % (i[0],i[1]) for i in route)
#else:
#    print "Failed (%s)" % result

